package cn.crm.controller;

import cn.crm.pojo.CstCustomer;
import cn.crm.pojo.CstService;
import cn.crm.pojo.SalPlan;
import cn.crm.service.CstCustomerService;
import cn.crm.service.SalPlanService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/CstCustomer")
public class CstCustomerController {
    @Autowired
    private CstCustomerService cstCustomerService;
    @PostMapping("/Page")
    public Page getPage(Page page){
        LambdaQueryWrapper<CstCustomer> lqw = new LambdaQueryWrapper<>();
        lqw.orderByAsc(CstCustomer::getCustId);
        return cstCustomerService.page(page,lqw);
    }
    @GetMapping("/Count")
    public List<CstCustomer> getCount(){
        return cstCustomerService.getCount();
    }
    @PostMapping("/ConditionSearch")
    public List<CstCustomer> getConditionSearchPage(@RequestBody HashMap condition){
        return cstCustomerService.getConditionSearchPage(condition);
    }
    @GetMapping("/{id}")
    public CstCustomer getById(@PathVariable Integer id){
        LambdaQueryWrapper<CstCustomer> lqw = new LambdaQueryWrapper<>();
        lqw.eq(CstCustomer::getCustId,id);
        return cstCustomerService.getOne(lqw);
    }
    @PostMapping
    public Boolean save(@RequestBody CstCustomer cstCustomer){
        return cstCustomerService.updateById(cstCustomer);
    }
}
